package com.skyon.rule.res;

import org.drools.builder.ResourceConfiguration;
import org.drools.builder.ResourceType;
import org.drools.io.Resource;
import org.drools.io.impl.ClassPathResource;
import org.drools.io.impl.UrlResource;


public class ResourceAdapter {
    private Resource              resource;
    private ResourceType          resourceType;
    private ResourceConfiguration resourceConfiguration;

    public ResourceAdapter() {

    }

    public ResourceAdapter(String resource,
                                 ResourceType resourceType,
                                 ResourceConfiguration resourceConfiguration) {
        super();
        setResource( resource );
        this.resourceType = resourceType;
        this.resourceConfiguration = resourceConfiguration;
    }

    public void setResource(String resource) {
        if ( resource.trim().startsWith( "classpath:" ) ) {
            this.resource = new ClassPathResource( resource.substring( resource.indexOf( ':' ) + 1 ),
                                                   ClassPathResource.class.getClassLoader() );
        } else {
            this.resource = new UrlResource( resource );
        }
    }

    public ResourceAdapter(String resource,
                                 ResourceType resourceType) {
        this( resource,
              resourceType,
              null );
    }

    public ResourceAdapter(String resource) {
        this( resource,
              ResourceType.DRL,
              null );
    }

    public ResourceAdapter(String resource,
                                 String resourceType,
                                 ResourceConfiguration resourceConfiguration) {
        this( resource,
              ResourceType.getResourceType( resourceType ),
              resourceConfiguration );
    }

    public ResourceAdapter(String resource,
                                 String resourceType) {
        this( resource,
              resourceType,
              null );
    }

    public Resource getDroolsResource() {
        return resource;
    }

    public ResourceType getResourceType() {
        return resourceType;
    }

    public void setResourceType(ResourceType resourceType) {
        this.resourceType = resourceType;
    }

    public ResourceConfiguration getResourceConfiguration() {
        return resourceConfiguration;
    }

    public void setResourceConfiguration(ResourceConfiguration resourceConfiguration) {
        this.resourceConfiguration = resourceConfiguration;
    }

	public Resource getResource() {
		return resource;
	}

	public void setResource(Resource resource) {
		this.resource = resource;
	}

}
